package com.ruoyi.web.controller.dmpdatacollect;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dmp.common.util.DmpDateTimeUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmpdatacollect.domain.DmpDcollectTask;
import com.ruoyi.dmpdatacollect.service.IDmpDcollectTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集任务Controller
 * 
 * @author MquanZeng
 * @date 2021-12-17
 */
@RestController
@RequestMapping("/dmpdatacollect/task")
public class DmpDcollectTaskController extends BaseController
{
    @Autowired
    private IDmpDcollectTaskService dmpDcollectTaskService;

    /**
     * 查询数据采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmpDcollectTask dmpDcollectTask)
    {
        startPage();
        List<DmpDcollectTask> list = dmpDcollectTaskService.selectDmpDcollectTaskList(dmpDcollectTask);
        return getDataTable(list);
    }

    /**
     * 导出数据采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:export')")
    @Log(title = "数据采集任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmpDcollectTask dmpDcollectTask)
    {
        List<DmpDcollectTask> list = dmpDcollectTaskService.selectDmpDcollectTaskList(dmpDcollectTask);
        ExcelUtil<DmpDcollectTask> util = new ExcelUtil<DmpDcollectTask>(DmpDcollectTask.class);
        util.exportExcel(response, list, "数据采集任务数据");
    }

    /**
     * 获取数据采集任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Integer taskId)
    {
        return AjaxResult.success(dmpDcollectTaskService.selectDmpDcollectTaskByTaskId(taskId));
    }

    /**
     * 新增数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:add')")
    @Log(title = "数据采集任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmpDcollectTask dmpDcollectTask)
    {
        return dmpDcollectTaskService.insertDmpDcollectTask(dmpDcollectTask);
    }

    /**
     * 修改数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:edit')")
    @Log(title = "数据采集任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmpDcollectTask dmpDcollectTask)
    {
        return dmpDcollectTaskService.updateDmpDcollectTask(dmpDcollectTask);
    }

    /**
     * 删除数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:remove')")
    @Log(title = "数据采集任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Integer[] taskIds)
    {
        return toAjax(dmpDcollectTaskService.deleteDmpDcollectTaskByTaskIds(taskIds));
    }


    /**
     * 复制数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:task:copy')")
    @GetMapping(value = "/copy/{taskId}")
    public AjaxResult copyTask(@PathVariable Integer taskId)
    {
        return dmpDcollectTaskService.copyTask(taskId);
    }


}
